#include "slepui.h"
#include "filetable.h"

SLEPUI::SLEPUI(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{

	setupLogger();
	setupWorkspacePanel();
	setupActions();
	setupMenus();

	setCentralWidget(new InfoWidget);
	resize(800,600);
}

SLEPUI::~SLEPUI(){
}

void SLEPUI::about(){
	QMessageBox::about(this, tr("About SLEP"),
		 tr("The <b>SLEP</b> is a sparse learning package "
			"used to solve dense and sparse systems, for a sparse solution."));
}



void SLEPUI::writeToCurrentDir(SLEPItem *item, QString& file){
	if(item->type == SLEPItem::SINGLE_VALUE){
		QStandardItemModel* itemModel = fileTable->getItemModel();
		QList<SLEPItem>* slepItemList = fileTable->getSlepItemList();
		itemModel->insertRow(0);
		slepItemList->insert(0,*item);
		itemModel->setData(itemModel->index(0,0),file);
		//itemModel->setData(itemModel->index(0,1),"Scalar");
		itemModel->setData(itemModel->index(0,1),QString(SLEPItem::TYPES_LONG[slepItemList->at(0).type]));
		itemModel->setData(itemModel->index(0,2),item->singlevalue);
		itemModel->setData(itemModel->index(0,3),tr("Not written to file."));
	}else if(item->type != SLEPItem::NONE){
		QStandardItemModel* itemModel = fileTable->getItemModel();
		QList<SLEPItem>* slepItemList = fileTable->getSlepItemList();
		QString fileName(*(FileTable::outputDir));
		fileName.append("\\");
		fileName.append(file);
		FileOperations::writeTextFile(*item,fileName);
		itemModel->insertRow(0);
		slepItemList->insert(0,*item);
		itemModel->setData(itemModel->index(0,0),QFileInfo(fileName).baseName());
		itemModel->setData(itemModel->index(0,1),QString(SLEPItem::TYPES_LONG[slepItemList->at(0).type]));
		itemModel->setData(itemModel->index(0,2),item->info());
		itemModel->setData(itemModel->index(0,3),QFileInfo(fileName).canonicalFilePath());
	}
}